import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, RouterStateSnapshot, Resolve} from '@angular/router';
import {Storage} from '@ionic/storage';
import {AppConfig} from '../common/app-config.enum';

@Injectable({
  providedIn: 'root'
})
export class UserTypeResolve implements Resolve<any> {

  constructor(
    private storage: Storage
  ) {
  }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<any> {
    return this.storage.get(AppConfig.USER_INFO)
      .then(userInfo => {
        return userInfo[AppConfig.USER_TYPE_KEY];
      });
  }

}
